package com.itheima.health.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Slf4j
public class ClearOrderSettingJob {
    @Reference
    private OrderSettingService orderSettingService;
    public void ClearOrderSettingByDate(){
        // 每个月最后一天凌晨2点执行一次清理任务
        // 获取日历对象
        Calendar instance = Calendar.getInstance();
        // 设置为上个月最后一天
        instance.set(Calendar.DAY_OF_MONTH,1);
        instance.add(Calendar.DATE,-1);

        Date date = instance.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        String lastDay = sdf.format(date);


        //测试
        lastDay = "2019-11-10";
        orderSettingService.delOrderSettingByLastDay(lastDay);
        log.info("[定时清理过期预约信息于]"+lastDay+"{已执行}");
    }



}
